package com.jweb.framework.config;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.enfry.common.util.config.Config;
import com.enfry.common.util.config.ConfigType;

public class PropertyConfigure extends PropertyPlaceholderConfigurer{
	private static final String mode_key = "common.environment";

     @Override  
     protected void processProperties(ConfigurableListableBeanFactory beanFactory,  
            Properties props) throws BeansException { 
    	 String mode = props.getProperty(mode_key); 
    	 Map<String, Object> properties = new HashMap<String, Object>();
    	 for(ConfigType config:ConfigType.values()){
    		 String properFile = String.format(config.getConfigFileName(), mode);
			 Map<String, Object> itemProperties = Config.getProperties(config, properFile);
			 properties.putAll(itemProperties);
 		}
    	 props.putAll(properties);
    	 super.processProperties(beanFactory, props);  
     }
}
